<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" class="boot">
    <head>
        <title>The Selenium Builder</title>
        <script type="text/javascript">
          // recorder.html is the webpage that's opened for the recorder window in
          // seleniumBuilder.js. That file then calls this file's window.boot functions.

          // Occasionally these windows come back after restart (despite being closed on
          // shutdown, presumably the session manager records the session too early)
          if (window.opener == null) {
            window.close();
          }

          /**
          * This function is called by the seleniumBuilder in XPI to open a bridge into chrome
          * code.
           *
           * The function keeps on being called on an interval to ensure the recorder window
           * is still available.
           *
           * The idea is to keep this file minimal and try and load everything dynamically.
           * The bridge parameter is the instance of seleniumBuilder that is being used to
           * coordinate things. The script parameter is the location of the script (if any)
           * being loaded in.
           * @param bridge The Selenium Builder (see seleniumBuilder.js)
           * @param script The script to load into the recorder on startup, if any.
           */
            window.boot = function (bridge, script) {
            // This function is called by an interval in seleniumBuilder.js, but after the first
            // time, we don't want to do anything - we don't want to load the script twice.
            if (window.booted) {
              return;
            }
            window.booted = true;
            clearTimeout(window.assumeDeadBy);

            /** Presents an error message for if we can't download the loader. */
            window.showLoadingErrorBeforeBody = function () {
              var div = document.getElementsByTagName('div')[0]
              div.innerHTML = 'Loading seems to have failed, perhaps the network is down?'
              div.className = "error"
            };

            window.assumeDeadBy = setTimeout(window.showLoadingErrorBeforeBody, 30000);

            // Set up global bridge: this allows the rest of the code to talk to the
            // seleniumBuilder to ask for things like Firefox preferences.
            window.bridge = bridge;

            // Record if we were booted with a particular script
            window.scriptBootedWith = script || null;

            // The last url that we were on - later overridden by step.js to provide info.
            // Used in seleniumBuilder.js to re-show the recorder window if it gets closed.
            window.lastSeenUrl = function () { return null; };

            // Load the loader script!
            var script = document.createElement('script');
            script.setAttribute('type', 'text/javascript');

            // Force no caching. This means the user always gets an up to date recorder.
            script.setAttribute('src', bridge.recorderURL() + "load.js?" + Math.random());

            // Above line may not work due to security reasons, so let's try a different
            // way too.
            document.getElementsByTagName('head')[0].appendChild(script);

            // Get a reference to the chrome window in which the recorder sits
            // (https://developer.mozilla.org/en/Working_with_windows_in_chrome_code)
            var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                                 .getInterface(Components.interfaces.nsIWebNavigation)
                                 .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                                 .rootTreeItem
                                 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                                 .getInterface(Components.interfaces.nsIDOMWindow);

            // Neaten the title of the recorder window
            mainWindow.title = "Selenium Builder";
            
            return true;
        }

        /**
        * Present an error message if we never get communicated with (can happen on a window
        * refresh).
        */
        window.assumeDeadBy = setTimeout(function () {
          var div = document.getElementsByTagName('div')[0]
          div.innerHTML = 'Loading seems to have failed, please try re-launching from Firefox'
          div.className = "error"
        }, 10000)
        </script>
        <style type="text/css">
            /* Let's not be ugly - visual changes should be replicated at the top of body.html */
            html.boot div {
              text-align: center;
              font-family: sans-serif;
              font-size: 18px;
              position: relative;
              top: 50%;
              margin-top: -9px;
              white-space: pre;
            }
            html.boot, html.boot body {
              position: absolute;
              top: 0px;
              bottom: 0px;
              right: 0px;
              left: 0px;
              background-color:#dddddd;
            }
            html.boot .error {
              color: red;
              white-space: normal;
            }
        </style>
    </head>
    <body>
      <center>
        <img src="html/img/builder-logo.png" style="margin-top: 70px">
        <div style="margin:20px;color:#333333;font-size:22px">Loading Selenium Builder...</div>
      </center>
    </body>
</html>
